package com.inforich.web.controller.disposal;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.disposal.domain.DisposalLand;
import com.inforich.disposal.service.IDisposalLandService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 处置地Controller
 *
 * @author hjm
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/disposal/disposalLand")
public class DisposalLandController extends BaseController {

  @Autowired
  private IDisposalLandService disposalLandService;

  /**
   * 所有资源利用化企业
   */
  @GetMapping("/all")
  public AjaxResult all(DisposalLand disposalLand) {
    Map<String, Object> map = beanToMap(disposalLand);
    List<DisposalLand> list = disposalLandService.listDisposalLand(map);
    return AjaxResult.success(list);
  }

  /**
   * 查询处置地列表
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:list')")
  @GetMapping("/list")
  public Page<DisposalLand> list(Page<DisposalLand> page, DisposalLand disposalLand) {
    Map<String, Object> map = beanToMap(disposalLand);
    disposalLandService.pageDisposalLand(page, map);
    return page;
  }


  /**
   * 导出处置地列表
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:export')")
  @Log(title = "处置地", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, DisposalLand disposalLand) {
    Map<String, Object> map = beanToMap(disposalLand);
    List<DisposalLand> list = disposalLandService.listDisposalLand(map);
    ExcelUtil<DisposalLand> util = new ExcelUtil<DisposalLand>(DisposalLand.class);
    util.exportExcel(response, list, "处置地数据");
  }

  /**
   * 获取处置地详细信息
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(disposalLandService.getDisposalLandById(id));
  }

  /**
   * 新增处置地
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:add')")
  @Log(title = "处置地", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody DisposalLand disposalLand) {
    String checkData = disposalLandService.checkData(disposalLand);
    if (StrUtil.isNotBlank(checkData)) {
      return AjaxResult.error(checkData);
    }
    return toAjax(disposalLandService.insertDisposalLand(disposalLand));
  }

  /**
   * 修改处置地
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:edit')")
  @Log(title = "处置地", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody DisposalLand disposalLand) {
    String checkData = disposalLandService.checkData(disposalLand);
    if (StrUtil.isNotBlank(checkData)) {
      return AjaxResult.error(checkData);
    }
    return toAjax(disposalLandService.updateDisposalLand(disposalLand));
  }

  /**
   * 删除处置地
   */
  @PreAuthorize("@ss.hasPermi('disposal:disposalLand:remove')")
  @Log(title = "处置地", businessType = BusinessType.DELETE)
  @DeleteMapping("/{id}")
  public AjaxResult remove(@PathVariable Long id) {
    return disposalLandService.removeDisposalLand(id);
  }
}
